
Ext.onReady(function(){

Ext.QuickTips.init();

var detailEl;


var contentPanel = {
id: 'content-panel',
region: 'center', // this is what makes this panel into a region within the containing layout
layout: 'card',
margins: '2 5 5 0',
activeItem: 0,
border: false,
items: [
// from basic.js:
start,material,configuracionCurso,grupoTrabajo,revisarArtefactos

]
};
	var encabezadoPanel = {
		id: 'encabezado-panel',
		region: 'center', // this is what makes this panel into a region within the containing layout
		//layout: 'card',
		//margins: '2 5 5 0',
		//activeItem: 0,
        split: true,
        height: 300,
        minSize: 150,
        autoScroll: true,
		border: false,
		items: [
			imagenLogo,
menu

		]
	};

// Go ahead and create the TreePanel now so that we can use it below
var treePanel = new Ext.tree.TreePanel({
	id: 'tree-panel',
	title: 'Perfil Profesor',
	region:'north',
	split: true,
	height: 300,
	minSize: 150,
	autoScroll: true,

	// tree-specific configs:
	rootVisible: false,
	//lines: false,
	//singleExpand: true,
	//useArrows: true,

	loader: new Ext.tree.TreeLoader({
		url: '../modulo_profesor/controlador/inicio.php',  
		baseParams: {accion:'arbolProfesor'}
	}),
	root: new Ext.tree.AsyncTreeNode()
});
var cursoConf='';

// Assign the changeLayout function to be called on tree node click.
treePanel.on('click', function(n){
	var sn = this.selModel.selNode || {}; // selNode is null on initial selection
	if(n.leaf && n.id != sn.id){  // ignore clicks on folders and currently selected node
                  var cadena=n.id;
                  var layout = cadena.split(" ");
                  viewlayout=layout[0];
                  cursoConf=layout[1];
                  //console.log(layout[0]);
				  
                  cargarFase(cursoConf);
                  cargarActividad(cursoConf);
                  cargarArtefacto(cursoConf);
				  cargarGrupos(cursoConf);
				  cargarEntregasGrupos(cursoConf);
                  //cargarOpcionesDeAcuerdoItem(cursoConf,viewlayout);
                  formCongifuracionMetodologiaCurso.getForm().load({params:{cfs_curso:cursoConf}});
				  cursoProfesor.load({params:{cursosProfesor:cursoConf}});
		Ext.getCmp('content-panel').layout.setActiveItem(viewlayout + '-panel');
	if(!detailEl){
		var bd = Ext.getCmp('details-panel').body;
		bd.update('').setStyle('background','#fff');
		detailEl = bd.createChild(); //create default empty div
	}
	detailEl.hide().update(Ext.getDom(viewlayout +'-details').innerHTML).slideIn('l', {stopFx:true,duration:.2});
	}
});

// This is the Details panel that contains the description for each example layout.
var detailsPanel = {
	id: 'details-panel',
	title: 'Informaci&oacute;n',
	region: 'center',
	bodyStyle: 'padding-bottom:15px;background:#eee;',
	autachanteoScroll: true,
	html: '<p class="details-info">Cuando seleccione alg\xFAn elemento del men&uacute; aqu\xED encontrara informaci&oacute;n.</p>'
};
//fin de arbol dinamico

// Finally, build the main layout once all the pieces are ready.  This is also a good
// example of putting together a full-screen BorderLayout within a Viewport.
new Ext.Viewport({
	layout: 'border',
	//title: 'Ext Layout Browser',
	items: [{
		
                                  //xtype: 'box',
                                  layout: 'menu',
                                  region: 'north',
                                  //applyTo: 'header',
                                  height: 80,
                                  width: 275,
                                  minSize: 100,
                                  maxSize: 500,
                                  items: [encabezadoPanel, 
                                  ]
		},{
		layout: 'border',
		id: 'layout-browser',
		region:'west',
		border: false,
		split:true,
		margins: '2 0 5 5',
		width: 275,
		minSize: 100,
		maxSize: 500,
		items: [treePanel, detailsPanel]
		},
		contentPanel
	],
	renderTo: Ext.getBody()
	});
});
function cargarFase(cursoConf)
{
    Ext.Ajax.request({
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarConfiguracionCursosFases', curso: cursoConf},
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
            consultaFasesCurso.loadData(responseData);
        },
        failure: function(f, a)
        {
          alert("Sos una !!!!");
          }
                                             
      });
}
function cargarActividad(cursoConf)
{
    Ext.Ajax.request({
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarConfiguracionCursosActividades', curso: cursoConf},
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
            consultaActividad.loadData(responseData);
        },
        failure: function(f, a)
        {
          //alert("Sos una !!!!");
          }
                                             
      });
}
function cargarArtefacto(cursoConf)
{
    Ext.Ajax.request({
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarConfiguracionCursosArtefactos', curso: cursoConf},
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
            consultaArtefacto.loadData(responseData);
        },
        failure: function(f, a)
        {
          //alert("Sos una !!!!");
          }
                                             
      });
}

function cargarGrupos(cursoConf)
{
    Ext.Ajax.request({
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarGrupo', curso: cursoConf},
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
            gruposTrabajoStore.loadData(responseData);
        },
        failure: function(f, a)
        {
          //alert("Sos una !!!!");
          }
                                             
      });
}

function cargarEntregasGrupos(cursoConf)
{
    Ext.Ajax.request({
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarEntregasGruposTrabajo', curso: cursoConf},
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText)
            consultaEntregas.loadData(responseData);
        },
        failure: function(f, a)
        {
          //alert("Sos una !!!!");
          }
                                             
      });
}

/*
function cargarOpcionesDeAcuerdoItem(cursoConf,viewlayout)
{      var nombreAccion;
var cursosCF;
alert(cursoConf);
	if(viewlayout=='material')
     {
	 storematerial.load();
	 }
    else if(viewlayout=='grupoTrabajo')
    {
		nombreAccion='consultarGrupo';
		cursosCF=cursoConf;
	}
    Ext.Ajax.request({
	//console.log("dato"+nombreAccion+"datp cruso"+cursosCF);
        url: '../modulo_profesor/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion:nombreAccion, curso:cursosCF },
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
			gruposTrabajoStore.load(responseData);
            //consultaFasesCurso.loadData(responseData);
        },
        failure: function(f, a)
        {
          alert("Sos una !!!!");
          }
                                             
      });
}*/
